package priv.mill.inner;

import java.util.Arrays;
import java.util.Random;

public class MyBooksSort {
	
	
	Book[] books=new Book[100];
	int top;
	
	public static void main(String[] args) {
		MyBooksSort myBooksSort=new MyBooksSort();
		Random random = new Random();
		
		for (int i = 0; i < 10; i++) {
			myBooksSort.add(new Book(random.nextInt(100), ((char)random.nextInt(130))+"java"));
		}
		myBooksSort.print();
		myBooksSort.sort();
		myBooksSort.print();
		
	}


	private void sort() {
		int out,in;
		for (out=top-1;out>0;out--) {
			for (in=0;in<out;in++) {
				if(compoetor(books[in],books[in+1])>0)
					warp(in,in+1);
			}
		}
	}


	private int compoetor(Book book, Book book2) {
		return (int) (book.price-book2.price);
	}




	private void warp(int in, int i) {
		Book temp = books[in];
		books[in]=books[i];
		books[i]=temp;
	}


	private void print() {
		System.out.println(Arrays.toString(books));
		
	}


	private void add(Book book) {
		books[top++]=book;
	}
}
